//
//  MineViewController.m
//  YongChuanTradingArea
//
//  Created by 李冰 on 2017/9/8.
//  Copyright © 2017年 李冰. All rights reserved.
//

#import "MineViewController.h"
#import "MineCell.h"
#import "MineHeaderView.h"
#import "UINavigationBar+LBExtend.h"
#import "MineAccountViewController.h"
#import "MineMsgViewController.h"
//#import "MineWalletViewController.h"
#import "MineMediaViewController.h"
#import "MediaViewController.h"
#import "MineNoticeViewController.h"
#import "MineCertificationViewController.h"

static NSString * const MineCellID = @"MineCell";

@interface MineViewController ()

@property (nonatomic, strong) MineHeaderView *headerView;

@property (nonatomic, strong) NSArray *iconArray;

@property (nonatomic, strong) NSArray *titleArray;

@end

@implementation MineViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.headerView.model = [LBUserManage defaultManager].userModel;
    self.navigationController.navigationBar.hidden = YES;
    self.navigationController.navigationBar.translucent = YES;
    
//    [LBNetworkingInstance requestGET:getMenberInfo parameters:@{@"id":[LBUserManage defaultManager].user_id} showHUD:YES success:^(id  _Nonnull responseObject, NSInteger code, NSString * _Nonnull message) {
//        
//        if (code == YCNetworkingStatusCodeSuccess)
//        {
//            
//        }
//    }];
    [LBNetworkingInstance requestGET:getMenberInfo parameters:@{@"id":[LBUserManage defaultManager].user_id?:@""} showHUD:YES success:^(id  _Nonnull responseObject, NSInteger code, NSString * _Nonnull message) {
        if (code == YCNetworkingStatusCodeSuccess){
            UserModel *userModel = [UserModel yy_modelWithJSON:responseObject[@"Data"]];
            [LBUserManage defaultManager].userModel = userModel;
            
        }
    }];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.titleView = [UIView new];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self setupArray];
    [self createUI];
        // Do any additional setup after loading the view.
}

- (void)createUI{
    [self.view addSubview:self.tableView];
    self.tableView.frame = CGRectMake(0, 0, lbScreenWidth, lbScreenHeight-lbTabbarHeight);
    self.tableView.rowHeight = 54.5;
    self.tableView.scrollEnabled = NO;
    self.headerView = [[NSBundle mainBundle]loadNibNamed:@"MineHeaderView" owner:nil options:nil].lastObject;
    UITapGestureRecognizer * tapGR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headerViewAction)];
    [self.headerView addGestureRecognizer:tapGR];
    [self.headerView.msgBtn addTarget:self action:@selector(msgAction) forControlEvents:UIControlEventTouchUpInside];
    self.tableView.tableHeaderView = self.headerView;
    [self.tableView registerNib:[UINib nibWithNibName:MineCellID bundle:nil] forCellReuseIdentifier:MineCellID];
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 12, 0, 0);
    self.tableView.separatorColor = [UIColor colorWithHexString:@"#dcdcdc"];

}

- (void)setupArray{
//    self.iconArray = @[@"ic_mine_wallet", @"ic_mine_media", @"ic_mine_book", @"ic_mine_notice", @"ic_mine_question", @"ic_mine_phone",@"ic_mine_about"];
//    self.titleArray = @[@"我的钱包", @"自媒体", @"我的资质", @"公告列表", @"常见问题", @"商户热线", @"关于我们"];
    
    self.iconArray = @[@"ic_mine_media", @"ic_mine_book", @"ic_mine_notice", @"ic_mine_question", @"ic_mine_phone",@"ic_mine_about"];
    self.titleArray = @[@"自媒体", @"我的资质", @"公告列表", @"常见问题", @"商户热线", @"检查更新"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titleArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    if (indexPath.row == 0) {
//        return CGFLOAT_MIN;
//    }
    return 54.5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MineCell *cell = [tableView dequeueReusableCellWithIdentifier:MineCellID forIndexPath:indexPath];
    cell.iconImgView.image = [UIImage imageNamed:self.iconArray[indexPath.row]];
    cell.titleLabel.text = self.titleArray[indexPath.row];

//    if (indexPath.row == 0) {
//        cell.hidden = YES;
//    }
    if (indexPath.row == 5) {
        cell.subtitleLabel.text = @"当前版本 v2.0.5";
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    if (indexPath.row == 0) {
//        MineWalletViewController *vc = [[MineWalletViewController alloc]init];
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//    }
//    if (indexPath.row == 1) {
//        MediaViewController *vc = [[MediaViewController alloc]init];
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//    }
//    if (indexPath.row == 2) {
//        MineCertificationViewController *vc = [[MineCertificationViewController alloc]init];
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//    }
//    if (indexPath.row == 3) {
//        MineNoticeViewController * vc = [[MineNoticeViewController alloc]init];
//        vc.msgType = @"1";
//        [self.navigationController pushViewController:vc animated:YES];
//    }
//    if (indexPath.row == 4) {
//        MineNoticeViewController * vc = [[MineNoticeViewController alloc]init];
//        vc.msgType = @"2";
//        [self.navigationController pushViewController:vc animated:YES];
//    }
//    if (indexPath.row == 5) {
//        NSString * str = [LBUserManage defaultManager].userModel.MOBILE;
//        if (str.length > 0) {
//            [LBTool callPhoneNumber:str];
//        }
//    }
//    if (indexPath.row == 6) {
//
//    }
    if (indexPath.row == 0) {
        MediaViewController *vc = [[MediaViewController alloc]init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (indexPath.row == 1) {
        MineCertificationViewController *vc = [[MineCertificationViewController alloc]init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (indexPath.row == 2) {
        MineNoticeViewController * vc = [[MineNoticeViewController alloc]init];
        vc.msgType = @"1";
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (indexPath.row == 3) {
        MineNoticeViewController * vc = [[MineNoticeViewController alloc]init];
        vc.msgType = @"2";
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (indexPath.row == 4) {
        NSString * str = [LBUserManage defaultManager].userModel.MOBILE;
        if (str.length > 0) {
            [LBTool callPhoneNumber:str];
        }
    }
    if (indexPath.row == 5) {
        
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - btn clicked
- (void)headerViewAction{
    MineAccountViewController * vc = [[MineAccountViewController alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)msgAction{
    MineMsgViewController * vc = [[MineMsgViewController alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    
    return UIStatusBarStyleLightContent;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
